package com.pocket.insight.base.config.mybatis;

import com.pocket.insight.base.config.mybatis.interceptor.ModelCommonInfoInterceptor;
import com.pocket.insight.base.config.mybatis.typeHandler.JsonTypeHandler;
import com.pocket.insight.entity.Connection;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.session.LocalCacheScope;
import org.apache.ibatis.type.TypeHandlerRegistry;
import org.mybatis.spring.boot.autoconfigure.ConfigurationCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 描述：
 *
 * @author shuize
 * @create 2024/12/26
 */
@Configuration
public class MybatisConfig {
    @Bean
    public ConfigurationCustomizer mybatisConfigurationCustomizer() {
        return configuration -> {
            configuration.setLocalCacheScope(LocalCacheScope.STATEMENT);
            TypeHandlerRegistry handlerRegistry = configuration.getTypeHandlerRegistry();
            handlerRegistry.register(Connection.ConnectionOptions.class, JsonTypeHandler.class);
        };
    }

    @Bean
    public Interceptor[] getInterceptors() {
        ModelCommonInfoInterceptor modelCommonInfoInterceptor = new ModelCommonInfoInterceptor();
        return new Interceptor[]{modelCommonInfoInterceptor};
    }
}
